import requests

# 去除warning
requests.packages.urllib3.disable_warnings()

url = "https://testpassport.rabbitpre.com/api/sso/login"
data = {
    "account": "xxx",
    "password": "xxx",
    "fromType": "pc"
}

User_Request_URL = "https://bws.test.rabbitpre.com/api/user"
orgID_Request_URL = "https://home.test.rabbitpre.com/api/workbench/org/getCompanyInfo?"


def user_login():

    session = requests.session()
    response = session.post(url, json=data, verify=False)
    # print(response.text)
    if response.json().get("errorCode") != "SUCCESS":
        raise EnvironmentError("登录失败")
    return session


def main():
    try:
        session = user_login()
        r_user = session.get(User_Request_URL, verify=False)
        r_orgID = session.get(orgID_Request_URL, verify=False)
        getUserid = r_user.json()["data"]["userId"]
        getorgID = r_orgID.json()["data"]["org_id"]

    except EnvironmentError as e:
        print(e)
    else:
        print('企业的userID =', getUserid)
        print('企业的orgID  =', getorgID)

main()







